<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class proyek_model extends CI_Model {

	function __construct()
	{
		parent::__construct();
		$this->CI = get_instance();
	}
	
	function insert($data) 
	{
        $this->db->insert('proyek', $data);
    }
	
	function update($id, $data) 
	{
        $this->db->where('ID_PROYEK', $id);
        $this->db->update('proyek', $data);
    }
	
	function delete($id) 
	{
        $this->db->where('ID_PROYEK', $id);
        $this->db->delete('proyek');
    }
	
	function get_data_all_proyek()
	{
		$this->db->select("*");
		$this->db->from('proyek');
		$query = $this->db->get();
		return $query;
	}
	
    //list flexy
    function get_data_proyek() 
	{
        //Select table name
        $table_name = "proyek";

        //Build contents query
        $this->db->select('*')->from($table_name);
        $this->CI->flexigrid->build_query();

        //Get contents
        $return['records'] = $this->db->get();

        //Build count query
        $this->db->select('*')->from($table_name);
        $this->CI->flexigrid->build_query(FALSE);

        $return['record_count'] = $this->db->count_all_results();

        //Return all
        return $return;
    }

    function selectone($id) 
	{
        $this->db->select("*");
        $this->db->from('proyek');
        $this->db->where('ID_PROYEK', $id);
        $query = $this->db->get();
        return $query;
    }
	
	function get_data_aktif_proyek()
	{
		$this->db->select("*");
		$this->db->from('proyek');
		$this->db->where('STATUS_PROYEK', 'Aktif');
		$this->db->order_by('NAMA_PROYEK', 'asc');		
		$query = $this->db->get();
		return $query;
	}
	
	function get_data_proyek_pegawai(){
		//Select table name
		$table_name = "proyek";
		
		//Build contents query
		$this->db->select('*')->from($table_name);
		$this->db->join('PEGAWAI AS H','proyek.ID_PEGAWAI = H.ID_PEGAWAI','left');
		// $this->db->where('status',  'Luar Biasa');
		$this->CI->flexigrid->build_query();
		
		//Get contents
		$return['records'] = $this->db->get();
		
		//Build count query
		$this->db->select('*')->from($table_name);
		$this->db->join('PEGAWAI AS H','proyek.ID_PEGAWAI = H.ID_PEGAWAI','left');
		// $this->db->where('status',  'Luar Biasa');
		$this->CI->flexigrid->build_query(FALSE);
		
		$return['record_count'] = $this->db->count_all_results();
	
		//Return all
		return $return;
	}	
	
	//list aktifitas
	function get_data_aktifitas()
	{
		//Select table name
		$table_name = "aktifitas";
		
		//Build contents query
		$this->db->select('*')->from($table_name);
		$this->CI->flexigrid->build_query();
		
		//Get contents
		$return['records'] = $this->db->get();
		
		//Build count query
		$this->db->select('*')->from($table_name);
                $this->CI->flexigrid->build_query(FALSE);
		
		$return['record_count'] = $this->db->count_all_results();
	
		//Return all
		return $return;
	}
	
	function cek_proyek_diaktifitas($id_proyek)
	{	
		$this->db->select('*');
		$this->db->from('aktifitas');
		$this->db->where('ID_PROYEK', $id_proyek);			
		$query = $this->db->get();
		if ($query->num_rows())
		{
			return FALSE;
		} else {
			return TRUE;
		}
	}
	
	//list evaluasi
	function get_data_evaluasi()
	{
		//Select table name
		$table_name = "evaluasi";
		
		//Build contents query
		$this->db->select('*')->from($table_name);
		$this->CI->flexigrid->build_query();
		
		//Get contents
		$return['records'] = $this->db->get();
		
		//Build count query
		$this->db->select('*')->from($table_name);
                $this->CI->flexigrid->build_query(FALSE);
		
		$return['record_count'] = $this->db->count_all_results();
	
		//Return all
		return $return;
	}
	
	function cek_proyek_dievaluasi($id_proyek)
	{	
		$this->db->select('*');
		$this->db->from('evaluasi');
		$this->db->where('ID_PROYEK', $id_proyek);			
		$query = $this->db->get();
		if ($query->num_rows())
		{
			return FALSE;
		} else {
			return TRUE;
		}
	}
	
}

?>